﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IronLua
{
    internal class Table
        : ITable
    {

        private readonly IDictionary<Value, Value> data;

        public Table(IDictionary<object, object> clrtable)
        {
            this.data = new ClrInteropDictionaryWrapper<object, object>(clrtable);
        }

        public Table(IDictionary<Value, Value> values)
        {
            this.data = new Dictionary<Value, Value>(8);
        }

        public Value this[Value key]
        { 
            get 
            {
                Value value;
                if (!this.data.TryGetValue(key, out value))
                {
                    return Value.DeadKey;
                }
                return value;
            } 
            set 
            {
                this.data[key] = value;    
            } 
        }

        public ITable Metatable { get; set; }
        ValueType   ILuaDynamicObject.Type { get { return ValueType.Table; } }
   
    }
}
